#!/bin/bash

#
function foo() {
  # 1. 过滤掉不需要的行信息
  egrep -v "^#|^$" /etc/elasticsearch/elasticsearch.yml
  # 过滤所有#号开始的行
  egrep -v "^*#|^$" /etc/elasticsearch/elasticsearch.yml
  # 2. 查看一个目录下多个目录下的信息
  ll /var/{lib,log}/elasticsearch/*
  # 3. 备份，后缀指定时间格式日期
  touch /tmp/test.yml
  cp /tmp/test.yml /tmp/test.yml-`date +%F`
  # or
  cp /tmp/{test.yml,test.yml2-`date +%F`}

  # 4. 获取服务器出网(公网)ip
  curl cip.cc
  # or
  curl ipinfo.io/ip

  # 5. 获取服务的完整日志信息
  systemctl status nginx -l

}

function common_use_command() {
# 1. 场景一：查找模糊匹配的文件，并进去压缩，压缩后再下载下来
datetime=2025-05-06
(find /data/logs -name "*$datetime*" -type f|xargs tar -cvf poc-helper-app-$datetime.tar) && mv  poc-helper-app-$datetime.tar /tmp && sz /tmp/poc-helper-app-$datetime.tar

# 查找今天的文件，并进行压缩
echo `date -d "1 days ago" +"%Y-%m-%d"`
(cd /tmp && find /data/logs/dispatcher-helper -type f -daystart -mtime 0|xargs tar -czvf poc-helper-app-`date +%Y-%m-%d`.tar.gz ) && sz /tmp/poc-helper-app-`date +%Y-%m-%d`.tar.gz

date 输出今天的年月日


# 场景2：查看TCP 建立的连接数
netstat -n|awk '/^tcp/ {++S[$NF]} END {for(a in S) print a,S[a] }'

# 指定时间段日志截取
sed -n '/2025-04-15 08:21:06/,/2025-04-15 08:28:06/p' fsis-nms-service-deployment-548889977c-g2zvn.log-2025-04-15-3 > /tmp/fsis-nms-service-deployment-548889977c-g2zvn.log


}


function loop() {
    # 简易的for 循环
    for i in {1..10};do echo $i;done
    for i in {1..10};do touch $i.txt;done

# 稍复杂的 for 循环
#!/bin/bash
for i in {1..60}; do
  if ! echo "Hello, World UDP" | nc -u -w 1 111.124.94.18 5090; then
    echo "UDP Failed to send" >&2
  fi

  if ! echo "Hello, World TCP" | nc  -w 1 111.124.94.18 5090; then
    echo "TCP Failed to send" >&2
  fi
  sleep 1
  echo $i
done
}


function windows_to_unix() {
    # 1. 解决Windows格式问题
    vim shenniu_publish.sh
    :set ff=unix  # 转换行尾符
    :wq
}

